package com.yukefms.rule;

import com.yukefms.engine.running.RunningContext;
import com.yukefms.engine.running.RunningEvent;
import com.yukefms.jointpoint.BodyPointCloud;
import com.yukefms.rule.formula.interfaces.DynamicBAFormula;
import com.yukefms.rule.formula.interfaces.StageBAFormula;
import com.yukefms.rule.formula.interfaces.StaticBAFormula;
import com.yukefms.rule.interfaces.BARule;
import com.yukefms.rule.interfaces.BAStageRule;
import com.yukefms.rule.state.BARuleState;
import com.yukefms.rule.state.RuleStateFlyWeight;

/**
 * @Description
 * @Author Ping
 * @Date 2021/6/29 7:16
 **/
public abstract class AbstractBARule implements BAStageRule {

    protected String ruleName ;
    protected double successScore ;
    protected BARuleState state ;

    public AbstractBARule() {

    }
    public AbstractBARule(String ruleName) {
        this.ruleName = ruleName ;
        this.state = RuleStateFlyWeight.getState(RuleStateFlyWeight.IN_ACTIVATED) ;
        System.out.println("State was created." + this.state) ;
        this.state.setRelatedRule(this);
    }
    public AbstractBARule(String ruleName, double successScore) {
        this(ruleName) ;
        this.successScore = successScore ;
    }

    @Override
    public String ruleName() {
        return this.ruleName;
    }

    @Override
    public abstract StaticBAFormula getTrigger() ;

    @Override
    public abstract  StaticBAFormula getResponse() ;

    @Override
    public abstract StaticBAFormula getInvariant() ;

    @Override
    public String getInvariantDescription() {
        return getInvariant().getDescription();
    }

    @Override
    public String getInvariantViolatedDesc() {
        return RunningEvent.EventContent.VIOLATED_SUFFIX + getInvariant().getDescription();
    }

    @Override
    public String getViolatedDesc(String actionName) {
        return RunningEvent.EventContent.VIOLATED_SUFFIX + actionName;
    }

    @Override
    public void doReaction(BodyPointCloud pointCloud, RunningContext context) {
        state.doReaction(pointCloud, context);
    }

    @Override
    public void setRuleState(BARuleState state) {
        this.state = state ;
        this.state.setRelatedRule(this);
    }


    @Override
    public BARuleState getRuleState() {
        return this.state;
    }

    @Override
    public void setSuccessScore(double score) {
        this.successScore = score ;
    }

    @Override
    public double successScore() {
        return this.successScore;
    }

    @Override
    public String getTriggerName() {
        return getTrigger().getName();
    }

    @Override
    public String getResponseName() {
        return getResponse().getName();
    }

    @Override
    public String getInvariantName() {
        return getInvariant().getName();
    }

    @Override
    public abstract DynamicBAFormula getDynamic() ;

    @Override
    public String getDynamicName() {
        return getDynamic().getName();
    }


    @Override
    public StageBAFormula currentStage() {
        return null;
    }

    @Override
    public boolean hasNextStage() {
        return false;
    }

    @Override
    public void toNextStage() {

    }

    @Override
    public BAStageRule addMoreStage(StageBAFormula formula) {
        return null;
    }
}
